package com.smarthome.common.httpwapper;

import org.apache.http.conn.ConnectionRequest;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class HttpClientConnectionPoolingAdapter extends PoolingHttpClientConnectionManager{

    private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientConnectionPoolingAdapter.class);
    
    @Override
    public ConnectionRequest requestConnection(
            final HttpRoute route,
            final Object state) {
        Long startTime=System.currentTimeMillis();
        ConnectionRequest cr=super.requestConnection(route, state);
        Long elapsedTime=System.currentTimeMillis()-startTime;
        if(elapsedTime>1000){
            LOGGER.info(String.format("从Http连接池中获取连接用时[%sms]",elapsedTime));            
        }
        return cr;
       
    }
}
